package com.fary.initializer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * 1.METE-INF/spring.factories
 * 2.application.addInitializers(new MyApplicationContextInitializer());
 * 3.context.initializer.classes=com.fary.initializer.MyApplicationContextInitializer
 */
public class MyApplicationContextInitializer implements ApplicationContextInitializer {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {

        // 打印人所有 beanName
        log.info(applicationContext.getBeanDefinitionCount() + "个Bean的名字如下：");
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanName : beanDefinitionNames) {
            log.info(beanName);
        }
    }
}
